package com.example.apple.zyfypt_902zl;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity {
    private EditText username;
    private EditText password;
    private Button btn_login;
    private Button btn_reg;
    private AmicoolListener<LoginBean> listener;
    private ResModel model;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        username=(EditText)findViewById(R.id.login_username);
        password=(EditText)findViewById(R.id.login_password);
        btn_login=(Button)findViewById(R.id.btn_login);
        btn_reg=(Button)findViewById(R.id.btn_reg);
        listener=new AmicoolListener<LoginBean>() {
            @Override
            public void onResponse(LoginBean l) {
                 if(l.getUsername()!=null){
                     String sessionid = l.getSessionid();

                     Intent intrnt =new Intent(LoginActivity.this,MainActivity.class);
                      finish();
                 }
                else{}
            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(LoginActivity.this,"用户名密码错误",
                Toast.LENGTH_SHORT).show();
            }
        };
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                model =new ResModel("gson");
                model.login(username.getText().toString(),password.getText().toString(),listener);
            }
        });

    }
}
